package com.sskj.qiangjin.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.qiangjin.bean.ImgUrlBean;
import com.sskj.qiangjin.http.HttpConfig;
import com.sskj.qiangjin.ui.fragment.AddPhotoFragment;

import java.io.File;


public class AddPhotoFragmentPresenter extends BasePresenter<AddPhotoFragment> {

    public void uploadImg(File file) {
        httpService.uploadImg(file)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.uploadSuccess((String) httpData.getData());
                        }
                    }
                });
    }

    public void uploadPhoto(String url) {
        httpService.uploadPhoto(url)
                .execute(new JsonCallBack<HttpData<ImgUrlBean>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<ImgUrlBean>> response) {
                        HttpData<ImgUrlBean> httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.success();
                        }
                    }
                });
    }
}
